{extend name="layout"}

{block name="content"}
	<form {if(empty($row))} action="{:url('admin/activity/save')}" {else /} action="{:url('admin/activity/update', ['id' => $row->id])}" {/if} method="post" enctype="multipart/form-data">
		<div class="form-group col-7">
			<label for="">活动分类</label>
			<select name="category_id" class="form-control" id="activity_category">
				{foreach $category as $v}
					<option value="{$v->id}" {:isset($row) && $row->category_id == $v->id? 'selected' : ''}>{$v->name}</option>
				{/foreach}
			</select>
		</div>

		<div class="form-group col-7">
			<label for="">类别</label>
			<select name="type" class="form-control" id="category_type">
				
			</select>
		</div>

		<div class="form-group col-7">
			<label for="">活动标题</label>
			<input type="text" class="form-control" name="title" value="{$row->title??''}">
		</div>
		<div class="form-group col-7">
			<label for="">明星(多个明星用逗号或者空格分开)</label>
			<input type="text" class="form-control" name="actor" value="{$row->actor??''}">
		</div>
		<div class="form-group col-7">
			<label for="">场馆</label>
			<input type="text" class="form-control" name="venues" value="{$row->venues??''}">
		</div>
		<div class="form-group col-7">
			<label for="">时间</label>
			<input type="datetime-local" class="form-control" name="begin_time" 
			value="{if(isset($row))}{:str_replace(' ', 'T', $row->begin_time)} {else /} {/if}">
		</div>
		<div class="form-group col-7">
			<label for="">票价(元 0代表免费活动)</label>
			<input type="number" class="form-control" name="fare" value="{$row->fare??0}">
		</div>

		<div class="form-group col-7">
			<label for="">积分兑换(0表示不允许积分兑换)</label>
			<input type="number" class="form-control" name="integral" value="{$row->integral??0}">
		</div>

		<div class="form-group col-7">
			<label for="">是否设为首页头条</label>
			<div>
			   <input type="radio" name="is_index_top" value=0 {:empty($row->is_index_top)? 'checked' : ''}> 否
			   <input type="radio" name="is_index_top" value=1 {:empty($row->is_index_top)? '':'checked'}> 是
			</div>
		</div>

		<div class="form-group col-7">
			<label for="">是否设为首页推荐</label>
			<div>
			   <input type="radio" name="is_index_recommend" value=0 {:empty($row->is_index_recommend)?'checked':''}> 否
			   <input type="radio" name="is_index_recommend" value=1 {:empty($row->is_index_recommend)?'':'checked'}> 是
			</div>
		</div>
		<div class="form-group col-7">
			<label for="">封面图</label>
			<input type="file" class="form-control" name="cover_pic">
			<div class="mt-2">
				{if(!empty($row->cover))}
				    <img src="/static/uploads/{$row->cover}" width=50 height="50">
				{/if}
			</div>
		</div>

		<div class="form-group col-7">
			<label for="">当前状态</label>
			<select name="status" class="form-control">
				{foreach $status as $k => $v}
					<option value="{$k}" {if !empty($row) && $row->status == $k} selected {/if}>{$v}</option>			
				{/foreach}
			</select>
		</div>

		<div class="form-group col-7">
			<label for="">描述</label>
			<textarea name="description"  cols="30" rows="10" class="form-control">{$row->description??''}</textarea>
		</div>
		{if isset($row)} <input type="hidden" name="_method" value="PUT"> {/if}
		<div class="form-group col-7">
		<label for=""></label>
		<button class="btn btn-primary" type="submit">确定</button>
		</div>

	</form>

	<script type="text/javascript">
	$(function(){
		$("#activity_category").on('change', function(e){
			let category_id = $(this).val();
			let url = "/admin/category_type/index/category_id/"+category_id;
			$.ajax({
				url:url,
				type:'get',
				success:function(res)
				{
					let str = '';
					res.forEach(function(v){
						//console.log(v);
						str += '<option value='+v.id+'>'+v.name+'</option>';
					})
					$("#category_type").empty().append(str);
				}
			});
		});
		
		$("#activity_category").trigger('change');
	})
	</script>
{/block}